package com.shop2cn.iapi.subscription.testcase;

import org.junit.After;

import com.shop2cn.iapi.subscription.parameter.*;
import com.shop2cn.iapi.subscription.service.*;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodmchSubscriptionService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.subscriptionfunc;
/**
*结束订购与试用Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_CloseSubscriptionAndTryout{
	private static CloseSubscriptionAndTryoutBean closesubscriptionandtryoutBean;
	private static CloseSubscriptionAndTryoutCall closesubscriptionandtryoutCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("结束订购与试用Test");
	}

	@Before
	public void caseUp() {
		closesubscriptionandtryoutBean=new CloseSubscriptionAndTryoutBean();
		closesubscriptionandtryoutCall=new CloseSubscriptionAndTryoutCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(closesubscriptionandtryoutCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_CloseSubscriptionAndTryout_001() {
		Logger.start(true,"正确数据，成功");
		try {
			Integer mchId = GodmchManageCallService.CreateAllMsgSellerMch().getMchId();
			//创建付费订单
			GodmchSubscriptionService.ApplyCharge(mchId,0,3);
			//付费订单回调通知
			GodmchSubscriptionService.ChargeNotify(mchId);
			
			subscriptionfunc subscriptionfunc = GodmchSubscriptionService.selectSubscriptionFuncByMchId(mchId).get(0);
			Logger.verifyEquals(mchId, subscriptionfunc.getMchId(), "验证mchid");
			Logger.verifyEquals(3, subscriptionfunc.getSubscriptionStatus(), "验证SubscriptionStatus");
			
			
			Logger.verifyEquals(1, GodmchSubscriptionService.UpdateSubscriptionTime(mchId), "验证修改成功");
			
			closesubscriptionandtryoutCall.setData(closesubscriptionandtryoutBean);
			closesubscriptionandtryoutCall.callService();			
			Logger.verifyEquals("ok", closesubscriptionandtryoutCall.getReturnData(), "验证code");
			
			subscriptionfunc = GodmchSubscriptionService.selectSubscriptionFuncByMchId(mchId).get(0);
			
			Logger.verifyEquals(mchId, subscriptionfunc.getMchId(), "验证mchid");
			Logger.verifyEquals(4, subscriptionfunc.getSubscriptionStatus(), "验证SubscriptionStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}